#!/usr/bin/make -f

install_dir=install -d -m 755
install_file=install -m 644
install_script=install -m 755
install_binary=install -m 755 -s

DEBVERSION := $(shell dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2)

build:

clean:
	$(checkdir)
	-rm -f  *~ */*~ debian/files* debian/*substvars
	-rm -rf debian/tmp

binary-indep: checkroot
	$(checkdir)
	-rm -rf debian/tmp

	$(install_dir) debian/tmp/DEBIAN/
	$(install_file) debian/conffiles debian/tmp/DEBIAN/
	$(install_script) debian/postinst debian/tmp/DEBIAN/
	$(install_script) debian/postrm debian/tmp/DEBIAN/

	$(install_dir) debian/tmp/etc/cron.d/
	$(install_file) etc/cron.d/* debian/tmp/etc/cron.d/

	$(install_dir) debian/tmp/usr/sbin/
	$(install_script) usr/sbin/* debian/tmp/usr/sbin/

	$(install_dir) debian/tmp/usr/share/backgrounds/
	$(install_file) usr/share/backgrounds/* debian/tmp/usr/share/backgrounds/

	$(install_dir) debian/tmp/usr/share/doc/eeepc-tweaks/
	$(install_file) debian/changelog debian/tmp/usr/share/doc/eeepc-tweaks/changelog.Debian
	gzip -9v debian/tmp/usr/share/doc/eeepc-tweaks/*
	$(install_file) debian/copyright debian/tmp/usr/share/doc/eeepc-tweaks/
	$(install_file) usr/share/doc/eeepc-tweaks/* debian/tmp/usr/share/doc/eeepc-tweaks/

	$(install_dir) debian/tmp/usr/share/gconf/defaults/
	$(install_file) usr/share/gconf/defaults/* debian/tmp/usr/share/gconf/defaults/

	dpkg-gencontrol -peeepc-tweaks

	chown -R root:root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

binary-arch:

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot
